package com.loadmore.oneday.fragment

import android.os.Bundle
import android.text.TextUtils
import com.alibaba.android.arouter.facade.annotation.Route
import com.loadmore.common.base.BaseAdapter
import com.loadmore.common.base.BaseListFragment
import com.loadmore.common.constants.Api
import com.loadmore.common.model.BaseResponse
import com.loadmore.common.net.Request
import com.loadmore.common.net.impl.JsonCallback
import com.loadmore.common.router.RouterPath
import com.loadmore.oneday.R
import com.loadmore.oneday.adapter.SportListAdapter
import com.loadmore.stepcount.Step
import com.lzy.okgo.model.Response

@Route(path = RouterPath.Sport)
class SportFragment:BaseListFragment() {
    override fun setAdapter(): BaseAdapter {
        return SportListAdapter(context!!)
    }

    override fun getLayoutId(): Int {
        return R.layout.fragment_sport
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val title = arguments?.getString("title")
        if (!TextUtils.isEmpty(title)) {
            actionBarTitle(title!!)
        }
        getSportList()


    }

    private fun getSportList() {
        Request.get(Api.step_count,object :JsonCallback<BaseResponse<List<Step>>>() {
            override fun onSuccess(response: Response<BaseResponse<List<Step>>>?) {
                val data = response?.body()?.data
                if (data != null && data.isNotEmpty()) {
                    adapter.append(data)
                }
            }


        })
    }

}